home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 21 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.4 KB

  1. Path: chronicle.mti.sgi.com!slsv6bt!kanze
  2. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: ANSI/ISO Exception Hierarchy
  5. Date: 09 Jan 1996 15:55:45 GMT
  6. Organization: SEL
  7. Approved: austern@mti.sgi.com
  8. Message-ID: <KANZE.96Jan9165545@slsvewt.lts.sel.alcatel.de>
  9. References: <4cgog4$jsq@netlab.cs.rpi.edu> <4cipio$pcj@netlab.cs.rpi.edu> <4crabd$91f@netlab.cs.rpi.edu> <4cteo4$32o@netlab.cs.rpi.edu>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. In-Reply-To: Etay_Bogner@mail.stil.scitex.com's message of 9 Jan 1996 10:06:59 -0000
  12.  
  13.  
  14.  
  15. In article <4cteo4$32o@netlab.cs.rpi.edu>
  16. Etay_Bogner@mail.stil.scitex.com (Etay Bogner) writes:
  17.  
  18. |> >> |> The design of the exception classes has changed since Plauger's book was
  19. |> >> |> written, and class "exception" no longer has a member function "raise".
  20. |> >> |> The exception classes now have only
  21. |> >> |>      default constructor
  22. |> >> |>      copy constructor
  23. |> >> |>      assignment operator
  24. |> >> |>      virtual destructor
  25. |> >> |>      virtual function "const char* what() const;"
  26. |> >> 
  27. |> >> |> The "what" function returns an implementation-defined null-terminated
  28. |> >> |> character string.
  29.  
  30. |> I would suggest that it will return a :
  31.  
  32. |> typeid(*this).name() 
  33.  
  34. |> as the standard default behavior. This way we don't add another global
  35. |> string to  the executable's data area, and we re-use the already existing
  36. |> string ( which represents the name of the exception ).
  37.  
  38. I don't think so.  I would expect that the actual string will depend
  39. upon the environment.  My interpretation of what is desirable is an
  40. outputtable string, which could potentially be part of an error
  41. message; the class name would hardly qualify.
  42.  
  43. In my own implementation, the string does depend on the environment
  44. (environment variables LC_ALL, LC_MESSAGE and LANG).  I would expect
  45. that this is the standard situation.
  46.  
  47. |> >> Does this include the constructors?  I don't see where this is stated in
  48. |> >> the draft, and as most of the constructors (except bad_alloc and
  49. |> >> bad_exception) take a reference to a string, I would expect them to
  50. |> >> invoke the copy constructor for string, which I presume *can* throw
  51. |> >> bad_alloc.
  52.  
  53. |> I believe that the string class would best implememnted as a
  54. |> copy-on-change class, which means that the copy-constructor will not
  55. |> actually duplicate the string but will increase the reference counter it
  56. |> uses.
  57.  
  58. I don't believe that copy on write is allowed in the current draft.
  59. Each string can have its own unique allocator; how do you implement
  60. copy on write in such cases?  (Hmmm...  Maybe this is the answer to my
  61. question.  The string in the exception class uses an allocator that
  62. gets its memory from a special pre-reserved area.)
  63.  
  64. Even if copy on write were allowed, I can think of many reasonable
  65. implementations in which string::data() (or string::c_str()) may throw
  66. bad_alloc.  Maintaining the physical data internally as a contiguous
  67. buffer makes most of the string manipulation functions relatively
  68. expensive on long strings.  (Since I only use very short strings, this
  69. doesn't bother me.  But it is a point that an implementor may want to
  70. consider.)
  71. --
  72. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  73. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  74. Conseils, itudes et rialisations en logiciel orienti objet --
  75.                 -- A la recherche d'une activiti dans une region francophone
  76.  
  77.  
  78.